var KOC = require("koc.common.utils");

var Mysql_Helper = null;
var DBName = null;

module.exports = {
    //region 初始化
    Init: function (sql_helper, dbname) {
        if (!Mysql_Helper) {
            Mysql_Helper = sql_helper;
            DBName = dbname;
        }
        return this;
    },
    //endregion
    //region Anchor_Day:艺人日报表
    Anchor_Day: {
        Scheduler: function (callback) {
            Mysql_Helper.ExecuteNonQuery(DBName, "CALL `proc_anchor_day`();", null, callback);
        },
        //region Info_BeansDurationMonth：艺人获得金豆数总值和直播总时长//1-上个月，2-本月
        Info_BeansDurationMonth: function (parm, callback) {
            var sql = "SELECT `TabA`.`Report_Day`" +
                ", SUM(`TabA`.`Beans_Anchor`) AS `Beans_Anchor`" +
                ", SUM(`TabA`.`Live_Duration`) AS `Live_Duration`" +
                ", SUM(`TabA`.`Live_Duration_Efftive`) AS `Live_Duration_Efftive`" +
                ", SUM(CASE WHEN `TabA`.`Live_Duration_Efftive` >= 120 THEN 1 ELSE 0 END) AS `Sum_Efftive`" +
                " FROM (SELECT `Report_Day`" +
                ", `User_ID`" +
                ", SUM(`Beans_Anchor_Task`) AS `Beans_Anchor`" +
                ", SUM(`Live_Duration`) AS `Live_Duration`" +
                ", SUM(`Live_Duration_Efftive`) AS `Live_Duration_Efftive`" +
                " FROM `anchor_day`" +
                " GROUP BY `Report_Day`, `User_ID`) AS `TabA`" +
                " WHERE `TabA`.`User_ID` = :User_ID";
            if (!KOC.Lodash.includes([1, 2, 3], parm.Month)) {
                callback(KOC.ReturnValue.New({
                    hasError: true,
                    message: "传入参数错误:Month"
                }));
                return;
            }
            if (parm.Month == 1) {
                sql += " AND DATE_FORMAT(`TabA`.`Report_Day`,'%Y-%c') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y-%c')";
            } else if (parm.Month == 2) {
                sql += " AND DATE_FORMAT(`TabA`.`Report_Day`,'%Y-%c') = DATE_FORMAT(NOW(),'%Y-%c')";
            } else if ((parm.Month == 3)) {
                sql += " AND DATE_FORMAT(`TabA`.`Report_Day`,'%Y-%c') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 2 MONTH),'%Y-%c')";
            }
            Mysql_Helper.ExecuteRow(DBName, sql, {User_ID: parm.User_ID}, callback);
        },
        //endregion
        //region Info_FamilyMonth：上个月内的公会的所有艺人总收入//1-上个月，2-本月
        Info_FamilyMonth: function (parm, callback) {
            var sql = "SELECT `Report_Day`" +
                ", `Family_ID`" +
                ", SUM(`Beans_Anchor_Task`) AS SUM_BeansAnchor" +
                " FROM `anchor_day`" +
                " WHERE `Family_ID` > 0";
            if (!KOC.Lodash.includes([1, 2], parm.Month)) {
                callback(KOC.ReturnValue.New({
                    hasError: true,
                    message: "传入参数错误:Month"
                }));
                return;
            }
            if (parm.Month == 1) {
                sql += " AND DATE_FORMAT(`Report_Day`,'%Y-%c') = DATE_FORMAT(DATE_SUB(NOW(),INTERVAL 1 MONTH),'%Y-%c')";
            } else {
                sql += " AND DATE_FORMAT(`Report_Day`,'%Y-%c') = DATE_FORMAT(NOW(),'%Y-%c')";
            }
            sql += " GROUP BY `Family_ID`";
            Mysql_Helper.ExecuteTable(DBName, sql, {}, callback);
        }
        //endregion
    },
    //endregion
    //region Anchor_Family_Month:艺人公会月报表
    Anchor_Family_Month: {
        Scheduler: function (callback) {
            Mysql_Helper.ExecuteNonQuery(DBName, "CALL `proc_anchor_family_month`();", null, callback);
        },
        //region List 公会艺人列表
        List: function (parm, callback) {
            parm = KOC.Lodash.extend({
                Limit: 0,//查询数量,默认100条
                User_ID: 0,//艺人ID
                NickName: null,//艺人昵称
                Family_ID: 0,//公会ID
                IsProtect: -1,//本月是否处于保护期
                IsProtectDue: -1,//本月是否脱离保护期
                Report_Day_Start: null,//开始时间
                Report_Day_End: null,//结束时间
                Order: null//排序,默认按时间倒叙艺人ID正序排列
            }, parm);
            parm.Limit = KOC.StringUtils.ToIntPositive(parm.Limit);
            parm.User_ID = KOC.StringUtils.ToIntPositive(parm.User_ID);
            parm.Family_ID = KOC.StringUtils.ToIntPositive(parm.Family_ID);
            parm.IsProtect = KOC.StringUtils.ToInt(parm.IsProtect, -1);
            parm.IsProtectDue = KOC.StringUtils.ToInt(parm.IsProtectDue, -1);
            var sql = "";
            //艺人ID
            if (parm.User_ID > 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`User_ID` = :User_ID", "AND");
            }
            //艺人昵称
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                sql = Mysql_Helper.AddToWhereSQL(sql, "`NickName` LIKE :NickName", "AND");
            }
            //公会ID
            if (parm.Family_ID > 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Family_ID` = :Family_ID", "AND");
            }
            //本月是否处于保护期
            if (parm.IsProtect >= 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`IsProtect` = :IsProtect", "AND");
            }
            //本月是否脱离保护期
            if (parm.IsProtectDue >= 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`IsProtectDue` = :IsProtectDue", "AND");
            }
            //时间过滤 开始时间
            if (parm.Report_Day_Start) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Report_Day` >= :Report_Day_Start", "AND");
            }
            //时间过滤 结束时间
            if (parm.Report_Day_End) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Report_Day` <= :Report_Day_End", "AND");
            }
            //排序
            switch (parm.Order) {
                case "User_ID":
                    parm.Order = "`User_ID` DESC, `Report_Day` DESC";
                    break;
                case "Family_ID":
                    parm.Order = "`Family_ID` DESC, `User_ID` DESC, `Report_Day` DESC";
                    break;
                default:
                    parm.Order = "`Report_Day` DESC, `User_ID` DESC, `Family_ID` DESC";
                    break;
            }
            sql = "SELECT *" +
                " FROM `anchor_family_month`" +
                (sql ? " WHERE " + sql : "") +
                " ORDER BY " + parm.Order +
                " LIMIT " + (parm.Limit || "500") + ";";
            Mysql_Helper.ExecuteTable(DBName, sql, parm, callback);
        }
        //endregion
    },
    //endregion
    //region Anchor_Month:艺人月报表
    Anchor_Month: {
        //region List 艺人薪资
        List: function (parm, callback) {
            parm = KOC.Lodash.extend({
                Limit: 0,//查询数量,默认100条
                User_ID: 0,//艺人ID
                Family_ID: 0,//公会ID
                IsProtect: -1,//本月是否处于保护期
                IsProtectDue: -1,//本月是否脱离保护期
                Report_Day_Start: null,//开始时间
                Report_Day_End: null,//结束时间
                Order: null//排序,默认按时间倒叙艺人ID正序排列
            }, parm);
            parm.Limit = KOC.StringUtils.ToIntPositive(parm.Limit);
            parm.User_ID = KOC.StringUtils.ToIntPositive(parm.User_ID);
            parm.Family_ID = KOC.StringUtils.ToIntPositive(parm.Family_ID);
            parm.IsProtect = KOC.StringUtils.ToInt(parm.IsProtect, -1);
            parm.IsProtectDue = KOC.StringUtils.ToInt(parm.IsProtectDue, -1);
            var sql = "";
            //艺人ID
            if (parm.User_ID > 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`User_ID` = :User_ID", "AND");
            }
            //公会ID
            if (parm.Family_ID > 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Family_ID` = :Family_ID", "AND");
            }
            //本月是否处于保护期
            if (parm.IsProtect >= 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`IsProtect` = :IsProtect", "AND");
            }
            //本月是否脱离保护期
            if (parm.IsProtectDue >= 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`IsProtectDue` = :IsProtectDue", "AND");
            }
            //时间过滤 开始时间
            if (parm.Report_Day_Start) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Report_Day` >= :Report_Day_Start", "AND");
            }
            //时间过滤 结束时间
            if (parm.Report_Day_End) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Report_Day` <= :Report_Day_End", "AND");
            }
            //排序
            switch (parm.Order) {
                case "User_ID":
                    parm.Order = "`User_ID` DESC, `Report_Day` DESC";
                    break;
                case "Family_ID":
                    parm.Order = "`Family_ID` DESC, `User_ID` DESC, `Report_Day` DESC";
                    break;
                default:
                    parm.Order = "`Report_Day` DESC, `User_ID` DESC";
                    break;
            }
            sql = "SELECT *" +
                " FROM `anchor_month`" +
                (sql ? " WHERE " + sql : "") +
                " ORDER BY " + parm.Order +
                " LIMIT " + (parm.Limit || "500") + ";";
            Mysql_Helper.ExecuteTable(DBName, sql, parm, callback);
        },
        //endregion
        //region Info 艺人信息
        Info: function (parm, callback) {
            parm = KOC.Lodash.extend({
                User_ID: 0,//艺人ID
                Report_Day: null//查询时间(某月,默认本月)
            }, parm);
            parm.User_ID = KOC.StringUtils.ToIntPositive(parm.User_ID);
            //查询时间(查询某一个月的艺人数据,默认本月)
            parm.Report_Day = parm.Report_Day ? KOC.Moment(new Date(parm.Report_Day)).format("YYYY-MM-01 00:00:00") : KOC.Moment().format("YYYY-MM-01 00:00:00");
            var sql = "SELECT *" +
                " FROM `anchor_month`" +
                " WHERE `User_ID` = :User_ID" +
                " AND `Report_Day` = :Report_Day" +
                " LIMIT 1;";
            Mysql_Helper.ExecuteRowCache(DBName, sql, parm, callback);
        }
        //endregion
    },
    //endregion
    //region Family_Month:公会月报表
    Family_Month: {
        //region List 公会收入
        List: function (parm, callback) {
            parm = KOC.Lodash.extend({
                Limit: 0,//查询数量,默认100条
                Family_ID: 0,//公会ID
                Report_Day_Start: null,//开始时间
                Report_Day_End: null//结束时间
            }, parm);
            parm.Family_ID = KOC.StringUtils.ToIntPositive(parm.Family_ID);
            parm.Limit = KOC.StringUtils.ToIntPositive(parm.Limit);
            var sql = "";
            //公会ID
            if (parm.Family_ID > 0) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Family_ID` = :Family_ID", "AND");
            }
            //时间过滤 开始时间
            if (parm.Report_Day_Start) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Report_Day` >= :Report_Day_Start", "AND");
            }
            //时间过滤 结束时间
            if (parm.Report_Day_End) {
                sql = Mysql_Helper.AddToWhereSQL(sql, "`Report_Day` <= :Report_Day_End", "AND");
            }
            sql = "SELECT *" +
                " FROM `family_month`" +
                (sql ? " WHERE " + sql : "") +
                " ORDER BY `Report_Day` DESC, `Family_ID` DESC" +
                " LIMIT " + (parm.Limit || "500") + ";";
            Mysql_Helper.ExecuteTable(DBName, sql, parm, callback);
        }
        //endregion
    },
    //endregion
    //region Platform_Day:平台总报表
    Platform_Day: {
        Scheduler: function (callback) {
            Mysql_Helper.ExecuteNonQuery(DBName, "CALL `proc_platform_day`();", null, callback);
        }
    },
    //endregion
    //region Channel_Day:渠道日报表
    Channel_Day: {
        Scheduler: function (callback) {
            Mysql_Helper.ExecuteNonQuery(DBName, "CALL `proc_channel_day`();", null, callback);
        },
        Update: function (Value, callback) {
            var sql = "INSERT INTO `channel_day`" +
                " (`Report_Day`" +
                ", `Channel_ID`" +
                ", `PV`" +
                ", `UV`" +
                ", `IP`)" +
                " VALUES (CURDATE()" +
                ", :Channel_ID" +
                ", :PV" +
                ", :UV" +
                ", :IP)" +
                " ON DUPLICATE KEY" +
                " UPDATE `PV` = `PV` + :PV" +
                ", `UV` = `UV` + :UV" +
                ", `IP` = `IP` + :IP;";
            Value = KOC.Lodash.extend({
                Channel_ID: null,
                PV: null,
                UV: null,
                IP: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion
    //region Channel_Strategy_Day:渠道流量策略日报表
    Channel_Strategy_Day: {
        Update: function (Value, callback) {
            var sql = "INSERT INTO `channel_strategy_day`" +
                " (`Report_Day`" +
                ", `Channel_ID`" +
                ", `Type`" +
                ", `User_ID`" +
                ", `Family_ID`" +
                ", `PV`)" +
                " VALUES (CURDATE()" +
                ", :Channel_ID" +
                ", :Type" +
                ", :User_ID" +
                ", :Family_ID" +
                ", 1)" +
                " ON DUPLICATE KEY" +
                " UPDATE `PV` = `PV` + 1;";
            Value = KOC.Lodash.extend({
                Channel_ID: null,
                Type: null,
                User_ID: null,
                Family_ID: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion


    //region Channel_Day_:渠道报表(改----)
    Channel_Day_: {
        Scheduler: function (callback) {
            Mysql_Helper.ExecuteNonQuery(DBName, "CALL `proc_channel_day_`();", null, callback);
        },
        Info_ChannelID: function (callback) {
            var sql = "SELECT sum(User_Count_SignUp) as Total_Count_SignUp,Channel_ID FROM `channel_day_` GROUP BY `Channel_ID` DESC";
            Mysql_Helper.ExecuteTable(DBName, sql, {}, callback);
        }
    },
    //endregion
    //region Page:分页
    Page: {
        //region AnchorFamilyDay:艺人日报表
        AnchorFamilyDay: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col.indexOf(':DIR:') > 0 ? page.Sort_Col.replace(/:DIR:/g, page.Sort_Dir) : page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnList = "*";
            PageParm.Condition = "";
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`NickName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`RealName` = :FuzzyQuery", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`User_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.User_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`User_ID` = :User_ID", "AND");
            }
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`NickName` LIKE :NickName", "AND");
            }
            if (parm.RealName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`RealName` = :RealName", "AND");
            }
            if (parm.Family_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_ID` = :Family_ID", "AND");
            }
            if (parm.Family_Name) {
                parm.Family_Name = "%" + parm.Family_Name + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_Name` LIKE :Family_Name", "AND");
            }
            var _Rating = [];
            KOC.Lodash.forEach(String(parm.Rating).split(","), function (ThisValue) {
                if (ThisValue != "") {
                    _Rating.push(ThisValue);
                }
            });
            if (_Rating.length > 0) {
                parm.Rating = _Rating;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Rating` IN (:Rating)", "AND");
            }
            parm.StartDate = KOC.DateUtils.Min(parm.StartDate);
            if (parm.StartDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` >= :StartDate", "AND");
            }
            parm.EndDate = KOC.DateUtils.Max(parm.EndDate);
            if (parm.EndDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` <= :EndDate", "AND");
            }
            PageParm.TableList = ", SUM(`Coin`) AS `Coin`" +
                ", SUM(`Coin_Task`) AS `Coin_Task`" +
                ", SUM(`Coin_Package`) AS `Coin_Package`" +
                ", SUM(`Coin_Package_Task`) AS `Coin_Package_Task`" +
                ", SUM(`Beans_Anchor`) AS `Beans_Anchor`" +
                ", SUM(`Beans_Anchor_Task`) AS `Beans_Anchor_Task`" +
                ", SUM(`Beans_Anchor_Package`) AS `Beans_Anchor_Package`" +
                ", SUM(`Beans_Anchor_Package_Task`) AS `Beans_Anchor_Package_Task`" +
                ", SUM(`Beans_Family`) AS `Beans_Family`" +
                ", SUM(`Beans_Family_Task`) AS `Beans_Family_Task`" +
                ", SUM(`Beans_Family_Package`) AS `Beans_Family_Package`" +
                ", SUM(`Beans_Family_Package_Task`) AS `Beans_Family_Package_Task`" +
                ", SUM(`Beans_Platform`) AS `Beans_Platform`" +
                ", SUM(`Beans_Platform_Task`) AS `Beans_Platform_Task`" +
                ", SUM(`Beans_Platform_Package`) AS `Beans_Platform_Package`" +
                ", SUM(`Beans_Platform_Package_Task`) AS `Beans_Platform_Package_Task`" +
                ", SUM(`Live_Count`) AS `Live_Count`" +
                ", SUM(`Live_Duration`) AS `Live_Duration`" +
                ", SUM(`Live_Duration_Efftive`) AS `Live_Duration_Efftive`" +
                ", SUM(`Gift_Count`) AS `Gift_Count`" +
                ", SUM(`Gift_Count_Task`) AS `Gift_Count_Task`" +
                ", SUM(`Gift_Count_Package`) AS `Gift_Count_Package`" +
                ", SUM(`Gift_Count_Package_Task`) AS `Gift_Count_Package_Task`" +
                ", SUM(`Gift_Count_Lucky`) AS `Gift_Count_Lucky`" +
                ", SUM(`Gift_Num`) AS `Gift_Num`" +
                ", SUM(`Gift_Num_Task`) AS `Gift_Num_Task`" +
                ", SUM(`Gift_Num_Package`) AS `Gift_Num_Package`" +
                ", SUM(`Gift_Num_Package_Task`) AS `Gift_Num_Package_Task`" +
                ", SUM(`Gift_Num_Lucky`) AS `Gift_Num_Lucky`" +
                ", SUM(`Gift_Coin`) AS `Gift_Coin`" +
                ", SUM(`Gift_Coin_Task`) AS `Gift_Coin_Task`" +
                ", SUM(`Gift_Coin_Package`) AS `Gift_Coin_Package`" +
                ", SUM(`Gift_Coin_Package_Task`) AS `Gift_Coin_Package_Task`" +
                ", SUM(`Gift_Coin_Lucky`) AS `Gift_Coin_Lucky`" +
                ", SUM(`Gift_Beans_Anchor`) AS `Gift_Beans_Anchor`" +
                ", SUM(`Gift_Beans_Anchor_Task`) AS `Gift_Beans_Anchor_Task`" +
                ", SUM(`Gift_Beans_Anchor_Package`) AS `Gift_Beans_Anchor_Package`" +
                ", SUM(`Gift_Beans_Anchor_Package_Task`) AS `Gift_Beans_Anchor_Package_Task`" +
                ", SUM(`Gift_Beans_Family`) AS `Gift_Beans_Family`" +
                ", SUM(`Gift_Beans_Family_Task`) AS `Gift_Beans_Family_Task`" +
                ", SUM(`Gift_Beans_Family_Package`) AS `Gift_Beans_Family_Package`" +
                ", SUM(`Gift_Beans_Family_Package_Task`) AS `Gift_Beans_Family_Package_Task`" +
                ", SUM(`Gift_Beans_Platform`) AS `Gift_Beans_Platform`" +
                ", SUM(`Gift_Beans_Platform_Task`) AS `Gift_Beans_Platform_Task`" +
                ", SUM(`Gift_Beans_Platform_Package`) AS `Gift_Beans_Platform_Package`" +
                ", SUM(`Gift_Beans_Platform_Package_Task`) AS `Gift_Beans_Platform_Package_Task`" +
                ", SUM(`Gift_Pond_Count`) AS `Gift_Pond_Count`" +
                ", SUM(`Gift_Pond_Coin`) AS `Gift_Pond_Coin`" +
                ", SUM(`Gift_Lucky_Coin`) AS `Gift_Lucky_Coin`" +
                ", SUM(`Guardian_Count`) AS `Guardian_Count`" +
                ", SUM(`Guardian_Coin`) AS `Guardian_Coin`" +
                ", SUM(`Guardian_Beans_Anchor`) AS `Guardian_Beans_Anchor`" +
                ", SUM(`Guardian_Beans_Family`) AS `Guardian_Beans_Family`" +
                ", SUM(`Guardian_Beans_Platform`) AS `Guardian_Beans_Platform`" +
                ", SUM(`Horn_Count`) AS `Horn_Count`" +
                ", SUM(`Horn_Count_Package`) AS `Horn_Count_Package`" +
                ", SUM(`Horn_Coin`) AS `Horn_Coin`" +
                ", SUM(`Horn_Coin_Package`) AS `Horn_Coin_Package`" +
                ", SUM(`Horn_Beans_Anchor`) AS `Horn_Beans_Anchor`" +
                ", SUM(`Horn_Beans_Anchor_Package`) AS `Horn_Beans_Anchor_Package`" +
                ", SUM(`Horn_Beans_Family`) AS `Horn_Beans_Family`" +
                ", SUM(`Horn_Beans_Family_Package`) AS `Horn_Beans_Family_Package`" +
                ", SUM(`Horn_Beans_Platform`) AS `Horn_Beans_Platform`" +
                ", SUM(`Horn_Beans_Platform_Package`) AS `Horn_Beans_Platform_Package`" +
                ", SUM(`Lottery_Coin`) AS `Lottery_Coin`" +
                ", SUM(`Lottery_CategoryIron_Coin`) AS `Lottery_CategoryIron_Coin`" +
                ", SUM(`Lottery_CategoryCopper_Coin`) AS `Lottery_CategoryCopper_Coin`" +
                ", SUM(`Lottery_CategorySilver_Coin`) AS `Lottery_CategorySilver_Coin`" +
                ", SUM(`Lottery_CategoryGold_Coin`) AS `Lottery_CategoryGold_Coin`" +
                ", SUM(`Lottery_Count`) AS `Lottery_Count`" +
                ", SUM(`Lottery_CategoryIron_Count`) AS `Lottery_CategoryIron_Count`" +
                ", SUM(`Lottery_CategoryCopper_Count`) AS `Lottery_CategoryCopper_Count`" +
                ", SUM(`Lottery_CategorySilver_Count`) AS `Lottery_CategorySilver_Count`" +
                ", SUM(`Lottery_CategoryGold_Count`) AS `Lottery_CategoryGold_Count`" +
                ", SUM(`Lottery_Winning_Amt`) AS `Lottery_Winning_Amt`" +
                ", SUM(`Lottery_CategoryIron_Winning_Amt`) AS `Lottery_CategoryIron_Winning_Amt`" +
                ", SUM(`Lottery_CategoryCopper_Winning_Amt`) AS `Lottery_CategoryCopper_Winning_Amt`" +
                ", SUM(`Lottery_CategorySilver_Winning_Amt`) AS `Lottery_CategorySilver_Winning_Amt`" +
                ", SUM(`Lottery_CategoryGold_Winning_Amt`) AS `Lottery_CategoryGold_Winning_Amt`" +
                ", SUM(`PV_ChannelStrategy`) AS `PV_ChannelStrategy`" +
                ", SUM(`PV_ChannelStrategy_Specific`) AS `PV_ChannelStrategy_Specific`" +
                ", SUM(`PV_ChannelStrategy_Recommend`) AS `PV_ChannelStrategy_Recommend`" +
                ", SUM(`PV_ChannelStrategy_WeekStar`) AS `PV_ChannelStrategy_WeekStar`" +
                ", SUM(`PV_ChannelStrategy_HotPrevious`) AS `PV_ChannelStrategy_HotPrevious`" +
                ", SUM(`PV_ChannelStrategy_Hot`) AS `PV_ChannelStrategy_Hot`" +
                ", SUM(`PV_ChannelStrategy_New`) AS `PV_ChannelStrategy_New`" +
                ", SUM(`PV_ChannelStrategy_Live`) AS `PV_ChannelStrategy_Live`" +
                ", SUM(`PV_ChannelStrategy_RoomID`) AS `PV_ChannelStrategy_RoomID`" +
                ", SUM(`PV_ChannelStrategy_Rating`) AS `PV_ChannelStrategy_Rating`" +
                ", SUM(`User_SignUp_Count`) AS `User_SignUp_Count`" +
                ", CASE SUM(`PV_ChannelStrategy`) WHEN 0 THEN 0 ELSE ROUND(SUM(`User_SignUp_Count`) / SUM(`PV_ChannelStrategy`), 6) END AS `User_SignUp_Rate_ChannelStrategy`";
            switch (parm.Group) {
                case "Day":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(DISTINCT `User_ID`) AS `User_ID_Count`" +
                        "  , '' AS `Rating`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        "  , COUNT(DISTINCT `Family_ID`) AS `Family_ID_Count`" +
                        PageParm.TableList +
                        " FROM `anchor_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`" +
                        ") AS `tabAnchorDay`";
                    PageParm.Condition = "";
                    break;
                case "User":
                    PageParm.ColumnPK = "`User_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , `User_ID`" +
                        "  , MAX(`NickName`) AS `NickName`" +
                        "  , '' AS `Rating`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        PageParm.TableList +
                        " FROM `anchor_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `User_ID`" +
                        ") AS `tabAnchorDay`";
                    PageParm.Condition = "";
                    break;
                case "Family":
                    PageParm.ColumnPK = "`Family_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(DISTINCT `User_ID`) AS `User_ID_Count`" +
                        "  , '' AS `Rating`" +
                        "  ,`Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        PageParm.TableList +
                        " FROM `anchor_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Family_ID`" +
                        ") AS `tabAnchorDay`";
                    PageParm.Condition = "";
                    break;
                case "Day-User":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , `User_ID`" +
                        "  , MAX(`NickName`) AS `NickName`" +
                        "  , '' AS `Rating`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        PageParm.TableList +
                        " FROM `anchor_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`, `User_ID`" +
                        ") AS `tabAnchorDay`";
                    PageParm.Condition = "";
                    break;
                case "Day-Family":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(`User_ID`) AS `User_ID_Count`" +
                        "  , '' AS `Rating`" +
                        "  , `Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        PageParm.TableList +
                        " FROM `anchor_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`, `Family_ID`" +
                        ") AS `tabAnchorDay`";
                    PageParm.Condition = "";
                    break;
                default:
                    PageParm.ColumnPK = "`User_ID`";
                    PageParm.TableList = "`anchor_day`";
                    break;
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        AnchorFamilyDay_Parm: function () {
            return {
                FuzzyQuery: "",
                User_ID: 0,
                NickName: "",
                RealName: "",
                Family_ID: 0,
                Family_Name: "",
                Rating: "",
                StartDate: "",
                EndDate: "",
                Group: ""
            };
        },
        //endregion
        //region AnchorFamilyMonth:艺人工会月报表
        AnchorFamilyMonth: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col.indexOf(':DIR:') > 0 ? page.Sort_Col.replace(/:DIR:/g, page.Sort_Dir) : page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnList = "*";
            PageParm.Condition = "";
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`NickName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`RealName` = :FuzzyQuery", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`User_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.User_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`User_ID` = :User_ID", "AND");
            }
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`NickName` LIKE :NickName", "AND");
            }
            if (parm.IsProtect >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsProtect` = :IsProtect", "AND");
            }
            if (parm.IsProtectDue >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsProtectDue` = :IsProtectDue", "AND");
            }
            var _Rating = [];
            KOC.Lodash.forEach(String(parm.Rating).split(","), function (ThisValue) {
                if (ThisValue != "") {
                    _Rating.push(ThisValue);
                }
            });
            if (_Rating.length > 0) {
                parm.Rating = _Rating;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Rating` IN (:Rating)", "AND");
            }
            if (parm.RealName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`RealName` = :RealName", "AND");
            }
            if (parm.Family_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_ID` = :Family_ID", "AND");
            }
            if (parm.Family_Name) {
                parm.Family_Name = "%" + parm.Family_Name + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_Name` LIKE :Family_Name", "AND");
            }
            if (parm.IsTaskBeans >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Task_Rate_Beans` " + (parm.IsTaskBeans ? ">= 1" : "< 1"), "AND");
            }
            if (parm.IsTaskLiveDay >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Task_Rate_LiveDay` " + (parm.IsTaskBeans ? ">= 1" : "< 1"), "AND");
            }
            if (parm.IsTaskLiveDuration >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Task_Rate_LiveDuration` " + (parm.IsTaskBeans ? ">= 1" : "< 1"), "AND");
            }
            if (parm.IsSalaryBase >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Salary_Base` " + (parm.IsSalaryBase ? ">" : "<=") + " 0", "AND");
            }
            parm.StartDate = KOC.DateUtils.Min(parm.StartDate);
            if (parm.StartDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` >= :StartDate", "AND");
            }
            parm.EndDate = KOC.DateUtils.Max(parm.EndDate);
            if (parm.EndDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` <= :EndDate", "AND");
            }
            PageParm.TableList = ", SUM(`Salary`) AS `Salary`" +
                ", SUM(`Salary_Base`) AS `Salary_Base`" +
                ", SUM(`Salary_BonusBeans`) AS `Salary_BonusBeans`" +
                ", SUM(`Income`) AS `Income`" +
                ", SUM(`Cost`) AS `Cost`" +
                ", SUM(`Cost_Anchor`) AS `Cost_Anchor`" +
                ", SUM(`Cost_Family`) AS `Cost_Family`" +
                ", SUM(`Profit`) AS `Profit`" +
                ", SUM(`Coin`) AS `Coin`" +
                ", SUM(`Coin_Task`) AS `Coin_Task`" +
                ", SUM(`Coin_Package`) AS `Coin_Package`" +
                ", SUM(`Coin_Package_Task`) AS `Coin_Package_Task`" +
                ", SUM(`Beans_Anchor`) AS `Beans_Anchor`" +
                ", SUM(`Beans_Anchor_Task`) AS `Beans_Anchor_Task`" +
                ", SUM(`Beans_Anchor_Package`) AS `Beans_Anchor_Package`" +
                ", SUM(`Beans_Anchor_Package_Task`) AS `Beans_Anchor_Package_Task`" +
                ", SUM(`Beans_Family`) AS `Beans_Family`" +
                ", SUM(`Beans_Family_Task`) AS `Beans_Family_Task`" +
                ", SUM(`Beans_Family_Package`) AS `Beans_Family_Package`" +
                ", SUM(`Beans_Family_Package_Task`) AS `Beans_Family_Package_Task`" +
                ", SUM(`Beans_Platform`) AS `Beans_Platform`" +
                ", SUM(`Beans_Platform_Task`) AS `Beans_Platform_Task`" +
                ", SUM(`Beans_Platform_Package`) AS `Beans_Platform_Package`" +
                ", SUM(`Beans_Platform_Package_Task`) AS `Beans_Platform_Package_Task`" +
                ", SUM(`Live_Count`) AS `Live_Count`" +
                ", SUM(`Live_Duration`) AS `Live_Duration`" +
                ", SUM(`Live_Duration_Efftive`) AS `Live_Duration_Efftive`" +
                ", SUM(`Live_Day`) AS `Live_Day`" +
                ", SUM(`Live_Day_Efftive`) AS `Live_Day_Efftive`" +
                ", SUM(`Gift_Count`) AS `Gift_Count`" +
                ", SUM(`Gift_Count_Task`) AS `Gift_Count_Task`" +
                ", SUM(`Gift_Count_Package`) AS `Gift_Count_Package`" +
                ", SUM(`Gift_Count_Package_Task`) AS `Gift_Count_Package_Task`" +
                ", SUM(`Gift_Count_Lucky`) AS `Gift_Count_Lucky`" +
                ", SUM(`Gift_Num`) AS `Gift_Num`" +
                ", SUM(`Gift_Num_Task`) AS `Gift_Num_Task`" +
                ", SUM(`Gift_Num_Package`) AS `Gift_Num_Package`" +
                ", SUM(`Gift_Num_Package_Task`) AS `Gift_Num_Package_Task`" +
                ", SUM(`Gift_Num_Lucky`) AS `Gift_Num_Lucky`" +
                ", SUM(`Gift_Coin`) AS `Gift_Coin`" +
                ", SUM(`Gift_Coin_Task`) AS `Gift_Coin_Task`" +
                ", SUM(`Gift_Coin_Package`) AS `Gift_Coin_Package`" +
                ", SUM(`Gift_Coin_Package_Task`) AS `Gift_Coin_Package_Task`" +
                ", SUM(`Gift_Coin_Lucky`) AS `Gift_Coin_Lucky`" +
                ", SUM(`Gift_Beans_Anchor`) AS `Gift_Beans_Anchor`" +
                ", SUM(`Gift_Beans_Anchor_Task`) AS `Gift_Beans_Anchor_Task`" +
                ", SUM(`Gift_Beans_Anchor_Package`) AS `Gift_Beans_Anchor_Package`" +
                ", SUM(`Gift_Beans_Anchor_Package_Task`) AS `Gift_Beans_Anchor_Package_Task`" +
                ", SUM(`Gift_Beans_Family`) AS `Gift_Beans_Family`" +
                ", SUM(`Gift_Beans_Family_Task`) AS `Gift_Beans_Family_Task`" +
                ", SUM(`Gift_Beans_Family_Package`) AS `Gift_Beans_Family_Package`" +
                ", SUM(`Gift_Beans_Family_Package_Task`) AS `Gift_Beans_Family_Package_Task`" +
                ", SUM(`Gift_Beans_Platform`) AS `Gift_Beans_Platform`" +
                ", SUM(`Gift_Beans_Platform_Task`) AS `Gift_Beans_Platform_Task`" +
                ", SUM(`Gift_Beans_Platform_Package`) AS `Gift_Beans_Platform_Package`" +
                ", SUM(`Gift_Beans_Platform_Package_Task`) AS `Gift_Beans_Platform_Package_Task`" +
                ", SUM(`Gift_Pond_Count`) AS `Gift_Pond_Count`" +
                ", SUM(`Gift_Pond_Coin`) AS `Gift_Pond_Coin`" +
                ", SUM(`Gift_Lucky_Coin`) AS `Gift_Lucky_Coin`" +
                ", SUM(`Guardian_Count`) AS `Guardian_Count`" +
                ", SUM(`Guardian_Coin`) AS `Guardian_Coin`" +
                ", SUM(`Guardian_Beans_Anchor`) AS `Guardian_Beans_Anchor`" +
                ", SUM(`Guardian_Beans_Family`) AS `Guardian_Beans_Family`" +
                ", SUM(`Guardian_Beans_Platform`) AS `Guardian_Beans_Platform`" +
                ", SUM(`Horn_Count`) AS `Horn_Count`" +
                ", SUM(`Horn_Count_Package`) AS `Horn_Count_Package`" +
                ", SUM(`Horn_Coin`) AS `Horn_Coin`" +
                ", SUM(`Horn_Coin_Package`) AS `Horn_Coin_Package`" +
                ", SUM(`Horn_Beans_Anchor`) AS `Horn_Beans_Anchor`" +
                ", SUM(`Horn_Beans_Anchor_Package`) AS `Horn_Beans_Anchor_Package`" +
                ", SUM(`Horn_Beans_Family`) AS `Horn_Beans_Family`" +
                ", SUM(`Horn_Beans_Family_Package`) AS `Horn_Beans_Family_Package`" +
                ", SUM(`Horn_Beans_Platform`) AS `Horn_Beans_Platform`" +
                ", SUM(`Horn_Beans_Platform_Package`) AS `Horn_Beans_Platform_Package`" +
                ", SUM(`Lottery_Coin`) AS `Lottery_Coin`" +
                ", SUM(`Lottery_CategoryIron_Coin`) AS `Lottery_CategoryIron_Coin`" +
                ", SUM(`Lottery_CategoryCopper_Coin`) AS `Lottery_CategoryCopper_Coin`" +
                ", SUM(`Lottery_CategorySilver_Coin`) AS `Lottery_CategorySilver_Coin`" +
                ", SUM(`Lottery_CategoryGold_Coin`) AS `Lottery_CategoryGold_Coin`" +
                ", SUM(`Lottery_Count`) AS `Lottery_Count`" +
                ", SUM(`Lottery_CategoryIron_Count`) AS `Lottery_CategoryIron_Count`" +
                ", SUM(`Lottery_CategoryCopper_Count`) AS `Lottery_CategoryCopper_Count`" +
                ", SUM(`Lottery_CategorySilver_Count`) AS `Lottery_CategorySilver_Count`" +
                ", SUM(`Lottery_CategoryGold_Count`) AS `Lottery_CategoryGold_Count`" +
                ", SUM(`Lottery_Winning_Amt`) AS `Lottery_Winning_Amt`" +
                ", SUM(`Lottery_CategoryIron_Winning_Amt`) AS `Lottery_CategoryIron_Winning_Amt`" +
                ", SUM(`Lottery_CategoryCopper_Winning_Amt`) AS `Lottery_CategoryCopper_Winning_Amt`" +
                ", SUM(`Lottery_CategorySilver_Winning_Amt`) AS `Lottery_CategorySilver_Winning_Amt`" +
                ", SUM(`Lottery_CategoryGold_Winning_Amt`) AS `Lottery_CategoryGold_Winning_Amt`" +
                ", SUM(`PV_ChannelStrategy`) AS `PV_ChannelStrategy`" +
                ", SUM(`PV_ChannelStrategy_Specific`) AS `PV_ChannelStrategy_Specific`" +
                ", SUM(`PV_ChannelStrategy_Recommend`) AS `PV_ChannelStrategy_Recommend`" +
                ", SUM(`PV_ChannelStrategy_WeekStar`) AS `PV_ChannelStrategy_WeekStar`" +
                ", SUM(`PV_ChannelStrategy_HotPrevious`) AS `PV_ChannelStrategy_HotPrevious`" +
                ", SUM(`PV_ChannelStrategy_Hot`) AS `PV_ChannelStrategy_Hot`" +
                ", SUM(`PV_ChannelStrategy_New`) AS `PV_ChannelStrategy_New`" +
                ", SUM(`PV_ChannelStrategy_Live`) AS `PV_ChannelStrategy_Live`" +
                ", SUM(`PV_ChannelStrategy_RoomID`) AS `PV_ChannelStrategy_RoomID`" +
                ", SUM(`PV_ChannelStrategy_Rating`) AS `PV_ChannelStrategy_Rating`" +
                ", SUM(`User_SignUp_Count`) AS `User_SignUp_Count`" +
                ", CASE SUM(`PV_ChannelStrategy`) WHEN 0 THEN 0 ELSE ROUND(SUM(`User_SignUp_Count`) / SUM(`PV_ChannelStrategy`), 6) END AS `User_SignUp_Rate_ChannelStrategy`";
            switch (parm.Group) {
                case "Month":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(DISTINCT `User_ID`) AS `User_ID_Count`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        "  , COUNT(DISTINCT `Family_ID`) AS `Family_ID_Count`" +
                        "  , -999 AS `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "User":
                    PageParm.ColumnPK = "`User_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , `User_ID`" +
                        "  , MAX(`NickName`) AS `NickName`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        "  , -999 AS `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `User_ID`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Family":
                    PageParm.ColumnPK = "`Family_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(DISTINCT `User_ID`) AS `User_ID_Count`" +
                        "  ,`Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        "  , -999 AS `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Family_ID`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Rating":
                    PageParm.ColumnPK = "`Rating`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(DISTINCT `User_ID`) AS `User_ID_Count`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        "  , COUNT(DISTINCT `Family_ID`) AS `Family_ID_Count`" +
                        "  , `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Rating`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Family-Rating":
                    PageParm.ColumnPK = "`Family_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(`User_ID`) AS `User_ID_Count`" +
                        "  , `Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        "  , `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Family_ID`, `Rating`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Month-User":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  , `User_ID`" +
                        "  , MAX(`NickName`) AS `NickName`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        "  , MAX(`Rating`) AS `Rating`" +
                        "  , MAX(`Rating_Date`) AS `Rating_Date`" +
                        "  , MAX(`IsProtect`) AS `IsProtect`" +
                        "  , MAX(`IsProtectDue`) AS `IsProtectDue`" +
                        "  , MAX(`Score`) AS `Score`" +
                        "  , MAX(`Score_Coin`) AS `Score_Coin`" +
                        "  , MAX(`Score_SignUp`) AS `Score_SignUp`" +
                        "  , MAX(`Task_Target_Salary`) AS `Task_Target_Salary`" +
                        "  , MAX(`Task_Target_Beans`) AS `Task_Target_Beans`" +
                        "  , MAX(`Task_Target_LiveDay`) AS `Task_Target_LiveDay`" +
                        "  , MAX(`Task_Target_LiveDuration`) AS `Task_Target_LiveDuration`" +
                        "  , MAX(`Task_Rate_Beans`) AS `Task_Rate_Beans`" +
                        "  , MAX(`Task_Rate_LiveDay`) AS `Task_Rate_LiveDay`" +
                        "  , MAX(`Task_Rate_LiveDuration`) AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`, `User_ID`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Month-Family":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(`User_ID`) AS `User_ID_Count`" +
                        "  , `Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        "  , -999 AS `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`, `Family_ID`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Month-Rating":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(`User_ID`) AS `User_ID_Count`" +
                        "  , `Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        "  , COUNT(DISTINCT `Family_ID`) AS `Family_ID_Count`" +
                        "  , `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`, `Rating`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Month-Family-Rating":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `User_ID`" +
                        "  , '' AS `NickName`" +
                        "  , COUNT(`User_ID`) AS `User_ID_Count`" +
                        "  , `Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        "  , `Rating`" +
                        "  , null AS `Rating_Date`" +
                        "  , -1 AS `IsProtect`" +
                        "  , -1 AS `IsProtectDue`" +
                        "  , -1 AS `Score`" +
                        "  , -1 AS `Score_Coin`" +
                        "  , -1 AS `Score_SignUp`" +
                        "  , -1 AS `Task_Target_Salary`" +
                        "  , -1 AS `Task_Target_Beans`" +
                        "  , -1 AS `Task_Target_LiveDay`" +
                        "  , -1 AS `Task_Target_LiveDuration`" +
                        "  , -1 AS `Task_Rate_Beans`" +
                        "  , -1 AS `Task_Rate_LiveDay`" +
                        "  , -1 AS `Task_Rate_LiveDuration`" +
                        PageParm.TableList +
                        " FROM `anchor_family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`, `Family_ID`, `Rating`" +
                        ") AS `tabAnchorFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                default:
                    PageParm.ColumnPK = "`User_ID`";
                    PageParm.TableList = "`anchor_family_month`";
                    break;
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        AnchorFamilyMonth_Parm: function () {
            return {
                FuzzyQuery: "",
                User_ID: 0,
                IsProtect: -1,
                IsProtectDue: -1,
                Rating: "",
                NickName: "",
                RealName: "",
                Family_ID: 0,
                Family_Name: "",
                IsTaskBeans: -1,
                IsTaskLiveDay: -1,
                IsTaskLiveDuration: -1,
                IsSalaryBase: -1,
                StartDate: "",
                EndDate: "",
                Group: ""
            };
        },
        //endregion
        //region FamilyMonth:工会月报表
        FamilyMonth: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col.indexOf(':DIR:') > 0 ? page.Sort_Col.replace(/:DIR:/g, page.Sort_Dir) : page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnList = "*";
            PageParm.Condition = "";
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Family_Name` LIKE :FuzzyQueryLike", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Family_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.Family_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_ID` = :Family_ID", "AND");
            }
            if (parm.Family_Name) {
                parm.Family_Name = "%" + parm.Family_Name + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_Name` LIKE :Family_Name", "AND");
            }
            parm.StartDate = KOC.DateUtils.Min(parm.StartDate);
            if (parm.StartDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` >= :StartDate", "AND");
            }
            parm.EndDate = KOC.DateUtils.Max(parm.EndDate);
            if (parm.EndDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` <= :EndDate", "AND");
            }
            PageParm.TableList = ", SUM(`Anchor_Count`) AS `Anchor_Count`" +
                ", SUM(`Anchor_Count_Live`) AS `Anchor_Count_Live`" +
                ", SUM(`Anchor_Count_TaskBeans`) AS `Anchor_Count_TaskBeans`" +
                ", SUM(`Anchor_Count_TaskLiveDay`) AS `Anchor_Count_TaskLiveDay`" +
                ", SUM(`Anchor_Count_TaskLiveDuration`) AS `Anchor_Count_TaskLiveDuration`" +
                ", SUM(`Anchor_Count_TaskAll`) AS `Anchor_Count_TaskAll`" +
                ", SUM(`Anchor_Count_SalaryBase`) AS `Anchor_Count_SalaryBase`" +
                ", SUM(`Anchor_Salary`) AS `Anchor_Salary`" +
                ", SUM(`Anchor_Salary_Base`) AS `Anchor_Salary_Base`" +
                ", SUM(`Anchor_Salary_BonusBeans`) AS `Anchor_Salary_BonusBeans`" +
                ", SUM(`Salary`) AS `Salary`" +
                ", SUM(`Salary_BonusBeans`) AS `Salary_BonusBeans`" +
                ", SUM(`Income`) AS `Income`" +
                ", SUM(`Cost`) AS `Cost`" +
                ", SUM(`Cost_Anchor`) AS `Cost_Anchor`" +
                ", SUM(`Cost_Family`) AS `Cost_Family`" +
                ", SUM(`Profit`) AS `Profit`" +
                ", SUM(`Coin`) AS `Coin`" +
                ", SUM(`Coin_Task`) AS `Coin_Task`" +
                ", SUM(`Coin_Package`) AS `Coin_Package`" +
                ", SUM(`Coin_Package_Task`) AS `Coin_Package_Task`" +
                ", SUM(`Beans_Anchor`) AS `Beans_Anchor`" +
                ", SUM(`Beans_Anchor_Task`) AS `Beans_Anchor_Task`" +
                ", SUM(`Beans_Anchor_Package`) AS `Beans_Anchor_Package`" +
                ", SUM(`Beans_Anchor_Package_Task`) AS `Beans_Anchor_Package_Task`" +
                ", SUM(`Beans_Family`) AS `Beans_Family`" +
                ", SUM(`Beans_Family_Task`) AS `Beans_Family_Task`" +
                ", SUM(`Beans_Family_Package`) AS `Beans_Family_Package`" +
                ", SUM(`Beans_Family_Package_Task`) AS `Beans_Family_Package_Task`" +
                ", SUM(`Beans_Platform`) AS `Beans_Platform`" +
                ", SUM(`Beans_Platform_Task`) AS `Beans_Platform_Task`" +
                ", SUM(`Beans_Platform_Package`) AS `Beans_Platform_Package`" +
                ", SUM(`Beans_Platform_Package_Task`) AS `Beans_Platform_Package_Task`" +
                ", SUM(`Live_Count`) AS `Live_Count`" +
                ", SUM(`Live_Duration`) AS `Live_Duration`" +
                ", SUM(`Live_Duration_Efftive`) AS `Live_Duration_Efftive`" +
                ", SUM(`Live_Day`) AS `Live_Day`" +
                ", SUM(`Live_Day_Efftive`) AS `Live_Day_Efftive`" +
                ", SUM(`Gift_Count`) AS `Gift_Count`" +
                ", SUM(`Gift_Count_Task`) AS `Gift_Count_Task`" +
                ", SUM(`Gift_Count_Package`) AS `Gift_Count_Package`" +
                ", SUM(`Gift_Count_Package_Task`) AS `Gift_Count_Package_Task`" +
                ", SUM(`Gift_Count_Lucky`) AS `Gift_Count_Lucky`" +
                ", SUM(`Gift_Num`) AS `Gift_Num`" +
                ", SUM(`Gift_Num_Task`) AS `Gift_Num_Task`" +
                ", SUM(`Gift_Num_Package`) AS `Gift_Num_Package`" +
                ", SUM(`Gift_Num_Package_Task`) AS `Gift_Num_Package_Task`" +
                ", SUM(`Gift_Num_Lucky`) AS `Gift_Num_Lucky`" +
                ", SUM(`Gift_Coin`) AS `Gift_Coin`" +
                ", SUM(`Gift_Coin_Task`) AS `Gift_Coin_Task`" +
                ", SUM(`Gift_Coin_Package`) AS `Gift_Coin_Package`" +
                ", SUM(`Gift_Coin_Package_Task`) AS `Gift_Coin_Package_Task`" +
                ", SUM(`Gift_Coin_Lucky`) AS `Gift_Coin_Lucky`" +
                ", SUM(`Gift_Beans_Anchor`) AS `Gift_Beans_Anchor`" +
                ", SUM(`Gift_Beans_Anchor_Task`) AS `Gift_Beans_Anchor_Task`" +
                ", SUM(`Gift_Beans_Anchor_Package`) AS `Gift_Beans_Anchor_Package`" +
                ", SUM(`Gift_Beans_Anchor_Package_Task`) AS `Gift_Beans_Anchor_Package_Task`" +
                ", SUM(`Gift_Beans_Family`) AS `Gift_Beans_Family`" +
                ", SUM(`Gift_Beans_Family_Task`) AS `Gift_Beans_Family_Task`" +
                ", SUM(`Gift_Beans_Family_Package`) AS `Gift_Beans_Family_Package`" +
                ", SUM(`Gift_Beans_Family_Package_Task`) AS `Gift_Beans_Family_Package_Task`" +
                ", SUM(`Gift_Beans_Platform`) AS `Gift_Beans_Platform`" +
                ", SUM(`Gift_Beans_Platform_Task`) AS `Gift_Beans_Platform_Task`" +
                ", SUM(`Gift_Beans_Platform_Package`) AS `Gift_Beans_Platform_Package`" +
                ", SUM(`Gift_Beans_Platform_Package_Task`) AS `Gift_Beans_Platform_Package_Task`" +
                ", SUM(`Gift_Pond_Count`) AS `Gift_Pond_Count`" +
                ", SUM(`Gift_Pond_Coin`) AS `Gift_Pond_Coin`" +
                ", SUM(`Gift_Lucky_Coin`) AS `Gift_Lucky_Coin`" +
                ", SUM(`Guardian_Count`) AS `Guardian_Count`" +
                ", SUM(`Guardian_Coin`) AS `Guardian_Coin`" +
                ", SUM(`Guardian_Beans_Anchor`) AS `Guardian_Beans_Anchor`" +
                ", SUM(`Guardian_Beans_Family`) AS `Guardian_Beans_Family`" +
                ", SUM(`Guardian_Beans_Platform`) AS `Guardian_Beans_Platform`" +
                ", SUM(`Horn_Count`) AS `Horn_Count`" +
                ", SUM(`Horn_Count_Package`) AS `Horn_Count_Package`" +
                ", SUM(`Horn_Coin`) AS `Horn_Coin`" +
                ", SUM(`Horn_Coin_Package`) AS `Horn_Coin_Package`" +
                ", SUM(`Horn_Beans_Anchor`) AS `Horn_Beans_Anchor`" +
                ", SUM(`Horn_Beans_Anchor_Package`) AS `Horn_Beans_Anchor_Package`" +
                ", SUM(`Horn_Beans_Family`) AS `Horn_Beans_Family`" +
                ", SUM(`Horn_Beans_Family_Package`) AS `Horn_Beans_Family_Package`" +
                ", SUM(`Horn_Beans_Platform`) AS `Horn_Beans_Platform`" +
                ", SUM(`Horn_Beans_Platform_Package`) AS `Horn_Beans_Platform_Package`" +
                ", SUM(`Lottery_Coin`) AS `Lottery_Coin`" +
                ", SUM(`Lottery_CategoryIron_Coin`) AS `Lottery_CategoryIron_Coin`" +
                ", SUM(`Lottery_CategoryCopper_Coin`) AS `Lottery_CategoryCopper_Coin`" +
                ", SUM(`Lottery_CategorySilver_Coin`) AS `Lottery_CategorySilver_Coin`" +
                ", SUM(`Lottery_CategoryGold_Coin`) AS `Lottery_CategoryGold_Coin`" +
                ", SUM(`Lottery_Count`) AS `Lottery_Count`" +
                ", SUM(`Lottery_CategoryIron_Count`) AS `Lottery_CategoryIron_Count`" +
                ", SUM(`Lottery_CategoryCopper_Count`) AS `Lottery_CategoryCopper_Count`" +
                ", SUM(`Lottery_CategorySilver_Count`) AS `Lottery_CategorySilver_Count`" +
                ", SUM(`Lottery_CategoryGold_Count`) AS `Lottery_CategoryGold_Count`" +
                ", SUM(`Lottery_Winning_Amt`) AS `Lottery_Winning_Amt`" +
                ", SUM(`Lottery_CategoryIron_Winning_Amt`) AS `Lottery_CategoryIron_Winning_Amt`" +
                ", SUM(`Lottery_CategoryCopper_Winning_Amt`) AS `Lottery_CategoryCopper_Winning_Amt`" +
                ", SUM(`Lottery_CategorySilver_Winning_Amt`) AS `Lottery_CategorySilver_Winning_Amt`" +
                ", SUM(`Lottery_CategoryGold_Winning_Amt`) AS `Lottery_CategoryGold_Winning_Amt`" +
                ", SUM(`PV_ChannelStrategy`) AS `PV_ChannelStrategy`" +
                ", SUM(`PV_ChannelStrategy_Specific`) AS `PV_ChannelStrategy_Specific`" +
                ", SUM(`PV_ChannelStrategy_Recommend`) AS `PV_ChannelStrategy_Recommend`" +
                ", SUM(`PV_ChannelStrategy_WeekStar`) AS `PV_ChannelStrategy_WeekStar`" +
                ", SUM(`PV_ChannelStrategy_HotPrevious`) AS `PV_ChannelStrategy_HotPrevious`" +
                ", SUM(`PV_ChannelStrategy_Hot`) AS `PV_ChannelStrategy_Hot`" +
                ", SUM(`PV_ChannelStrategy_New`) AS `PV_ChannelStrategy_New`" +
                ", SUM(`PV_ChannelStrategy_Live`) AS `PV_ChannelStrategy_Live`" +
                ", SUM(`PV_ChannelStrategy_RoomID`) AS `PV_ChannelStrategy_RoomID`" +
                ", SUM(`PV_ChannelStrategy_Rating`) AS `PV_ChannelStrategy_Rating`" +
                ", SUM(`User_SignUp_Count`) AS `User_SignUp_Count`" +
                ", CASE SUM(`PV_ChannelStrategy`) WHEN 0 THEN 0 ELSE ROUND(SUM(`User_SignUp_Count`) / SUM(`PV_ChannelStrategy`), 6) END AS `User_SignUp_Rate_ChannelStrategy`";
            switch (parm.Group) {
                case "Month":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , -1 AS `Family_ID`" +
                        "  , '' AS `Family_Name`" +
                        "  , COUNT(DISTINCT `Family_ID`) AS `Family_ID_Count`" +
                        PageParm.TableList +
                        " FROM `family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`" +
                        ") AS `tabFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                case "Family":
                    PageParm.ColumnPK = "`Family_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  ,`Family_ID`" +
                        "  , MAX(`Family_Name`) AS `Family_Name`" +
                        PageParm.TableList +
                        " FROM `family_month`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Family_ID`" +
                        ") AS `tabFamilyMonth`";
                    PageParm.Condition = "";
                    break;
                default:
                    PageParm.ColumnPK = "`Family_ID`";
                    PageParm.TableList = "`family_month`";
                    break;
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        FamilyMonth_Parm: function () {
            return {
                FuzzyQuery: "",
                Family_ID: 0,
                Family_Name: "",
                StartDate: "",
                EndDate: "",
                Group: ""
            };
        },
        //endregion
        //region ChannelDay:渠道日报表
        ChannelDay: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col.indexOf(':DIR:') > 0 ? page.Sort_Col.replace(/:DIR:/g, page.Sort_Dir) : page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnList = "*";
            PageParm.Condition = "";
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Channel_ID` LIKE :FuzzyQueryLike", "OR");
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.Channel_ID) {
                parm.Channel_ID += "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Channel_ID` LIKE :Channel_ID", "AND");
            }
            switch (parm.Effective) {
                case 1:
                    PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`PV` >= 100 OR `UV` >= 100 OR `IP` >= 100 OR `SignUp` >= 1", "AND");
                    break;
                case 0:
                    PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`PV` < 100 AND `UV` < 100 AND `IP` < 100 AND `SignUp` < 1", "AND");
                    break;
            }
            parm.StartDate = KOC.DateUtils.Min(parm.StartDate);
            if (parm.StartDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` >= :StartDate", "AND");
            }
            parm.EndDate = KOC.DateUtils.Max(parm.EndDate);
            if (parm.EndDate) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Report_Day` <= :EndDate", "AND");
            }
            PageParm.TableList = ", SUM(`PV`) AS `PV`" +
                ", SUM(`UV`) AS `UV`" +
                ", SUM(`IP`) AS `IP`" +
                ", SUM(`SignUp`) AS `SignUp`" +
                ", CASE SUM(`UV`) WHEN 0 THEN 0 ELSE ROUND(SUM(`SignUp`) / SUM(`UV`), 6) END AS `SignUp_Rate`" +
                ", MAX(`SignUp_Total`) AS `SignUp_Total`" +
                ", SUM(`SignUp_Phone`) AS `SignUp_Phone`" +
                ", MAX(`SignUp_Phone_Total`) AS `SignUp_Phone_Total`" +
                ", SUM(`SignUp_QQ`) AS `SignUp_QQ`" +
                ", MAX(`SignUp_QQ_Total`) AS `SignUp_QQ_Total`" +
                ", SUM(`SignUp_Weixin`) AS `SignUp_Weixin`" +
                ", MAX(`SignUp_Weixin_Total`) AS `SignUp_Weixin_Total`" +
                ", SUM(`SignUp_Weibo`) AS `SignUp_Weibo`" +
                ", MAX(`SignUp_Weibo_Total`) AS `SignUp_Weibo_Total`" +
                ", SUM(`SignUp_PC`) AS `SignUp_PC`" +
                ", MAX(`SignUp_PC_Total`) AS `SignUp_PC_Total`" +
                ", SUM(`SignUp_IOS`) AS `SignUp_IOS`" +
                ", MAX(`SignUp_IOS_Total`) AS `SignUp_IOS_Total`" +
                ", SUM(`SignUp_Android`) AS `SignUp_Android`" +
                ", MAX(`SignUp_Android_Total`) AS `SignUp_Android_Total`" +
                ", SUM(`SignUp_Retention_1`) AS `SignUp_Retention_1`" +
                ", SUM(`SignUp_PC_Retention_1`) AS `SignUp_PC_Retention_1`" +
                ", SUM(`SignUp_IOS_Retention_1`) AS `SignUp_IOS_Retention_1`" +
                ", SUM(`SignUp_Android_Retention_1`) AS `SignUp_Android_Retention_1`" +
                ", SUM(`SignUp_Retention_2`) AS `SignUp_Retention_2`" +
                ", SUM(`SignUp_PC_Retention_2`) AS `SignUp_PC_Retention_2`" +
                ", SUM(`SignUp_IOS_Retention_2`) AS `SignUp_IOS_Retention_2`" +
                ", SUM(`SignUp_Android_Retention_2`) AS `SignUp_Android_Retention_2`" +
                ", SUM(`SignUp_Retention_3`) AS `SignUp_Retention_3`" +
                ", SUM(`SignUp_PC_Retention_3`) AS `SignUp_PC_Retention_3`" +
                ", SUM(`SignUp_IOS_Retention_3`) AS `SignUp_IOS_Retention_3`" +
                ", SUM(`SignUp_Android_Retention_3`) AS `SignUp_Android_Retention_3`" +
                ", SUM(`SignUp_Retention_4`) AS `SignUp_Retention_4`" +
                ", SUM(`SignUp_PC_Retention_4`) AS `SignUp_PC_Retention_4`" +
                ", SUM(`SignUp_IOS_Retention_4`) AS `SignUp_IOS_Retention_4`" +
                ", SUM(`SignUp_Android_Retention_4`) AS `SignUp_Android_Retention_4`" +
                ", SUM(`SignUp_Retention_5`) AS `SignUp_Retention_5`" +
                ", SUM(`SignUp_PC_Retention_5`) AS `SignUp_PC_Retention_5`" +
                ", SUM(`SignUp_IOS_Retention_5`) AS `SignUp_IOS_Retention_5`" +
                ", SUM(`SignUp_Android_Retention_5`) AS `SignUp_Android_Retention_5`" +
                ", SUM(`SignUp_Retention_6`) AS `SignUp_Retention_6`" +
                ", SUM(`SignUp_PC_Retention_6`) AS `SignUp_PC_Retention_6`" +
                ", SUM(`SignUp_IOS_Retention_6`) AS `SignUp_IOS_Retention_6`" +
                ", SUM(`SignUp_Android_Retention_6`) AS `SignUp_Android_Retention_6`" +
                ", SUM(`SignUp_Retention_7`) AS `SignUp_Retention_7`" +
                ", SUM(`SignUp_PC_Retention_7`) AS `SignUp_PC_Retention_7`" +
                ", SUM(`SignUp_IOS_Retention_7`) AS `SignUp_IOS_Retention_7`" +
                ", SUM(`SignUp_Android_Retention_7`) AS `SignUp_Android_Retention_7`" +
                ", SUM(`SignUp_Retention_8`) AS `SignUp_Retention_8`" +
                ", SUM(`SignUp_PC_Retention_8`) AS `SignUp_PC_Retention_8`" +
                ", SUM(`SignUp_IOS_Retention_8`) AS `SignUp_IOS_Retention_8`" +
                ", SUM(`SignUp_Android_Retention_8`) AS `SignUp_Android_Retention_8`" +
                ", SUM(`SignUp_Retention_9`) AS `SignUp_Retention_9`" +
                ", SUM(`SignUp_PC_Retention_9`) AS `SignUp_PC_Retention_9`" +
                ", SUM(`SignUp_IOS_Retention_9`) AS `SignUp_IOS_Retention_9`" +
                ", SUM(`SignUp_Android_Retention_9`) AS `SignUp_Android_Retention_9`" +
                ", SUM(`SignUp_Retention_10`) AS `SignUp_Retention_10`" +
                ", SUM(`SignUp_PC_Retention_10`) AS `SignUp_PC_Retention_10`" +
                ", SUM(`SignUp_IOS_Retention_10`) AS `SignUp_IOS_Retention_10`" +
                ", SUM(`SignUp_Android_Retention_10`) AS `SignUp_Android_Retention_10`" +
                ", SUM(`SignUp_Retention_14`) AS `SignUp_Retention_14`" +
                ", SUM(`SignUp_PC_Retention_14`) AS `SignUp_PC_Retention_14`" +
                ", SUM(`SignUp_IOS_Retention_14`) AS `SignUp_IOS_Retention_14`" +
                ", SUM(`SignUp_Android_Retention_14`) AS `SignUp_Android_Retention_14`" +
                ", SUM(`SignUp_Retention_21`) AS `SignUp_Retention_21`" +
                ", SUM(`SignUp_PC_Retention_21`) AS `SignUp_PC_Retention_21`" +
                ", SUM(`SignUp_IOS_Retention_21`) AS `SignUp_IOS_Retention_21`" +
                ", SUM(`SignUp_Android_Retention_21`) AS `SignUp_Android_Retention_21`" +
                ", SUM(`SignUp_Retention_28`) AS `SignUp_Retention_28`" +
                ", SUM(`SignUp_PC_Retention_28`) AS `SignUp_PC_Retention_28`" +
                ", SUM(`SignUp_IOS_Retention_28`) AS `SignUp_IOS_Retention_28`" +
                ", SUM(`SignUp_Android_Retention_28`) AS `SignUp_Android_Retention_28`" +
                ", SUM(`SignUp_Retention_30`) AS `SignUp_Retention_30`" +
                ", SUM(`SignUp_PC_Retention_30`) AS `SignUp_PC_Retention_30`" +
                ", SUM(`SignUp_IOS_Retention_30`) AS `SignUp_IOS_Retention_30`" +
                ", SUM(`SignUp_Android_Retention_30`) AS `SignUp_Android_Retention_30`" +
                ", SUM(`SignIn`) AS `SignIn`" +
                ", SUM(`SignIn_PC`) AS `SignIn_PC`" +
                ", SUM(`SignIn_IOS`) AS `SignIn_IOS`" +
                ", SUM(`SignIn_Android`) AS `SignIn_Android`" +
                ", SUM(`Charge_UserCount`) AS `Charge_UserCount`" +
                ", SUM(`Charge_UserCount_First`) AS `Charge_UserCount_First`" +
                ", MAX(`Charge_UserCount_Total`) AS `Charge_UserCount_Total`" +
                ", SUM(`Charge_Count`) AS `Charge_Count`" +
                ", SUM(`Charge_Amt`) AS `Charge_Amt`" +
                ", SUM(`Charge_Coin`) AS `Charge_Coin`" +
                ", SUM(`Charge_Poundage`) AS `Charge_Poundage`" +
                ", SUM(`Income`) AS `Income`" +
                ", SUM(`Cost`) AS `Cost`" +
                ", SUM(`Profit`) AS `Profit`" +
                ", SUM(`Coin`) AS `Coin`" +
                ", SUM(`Coin_Return`) AS `Coin_Return`" +
                ", SUM(`Beans_Anchor`) AS `Beans_Anchor`" +
                ", SUM(`Beans_Family`) AS `Beans_Family`" +
                ", SUM(`Beans_Platform`) AS `Beans_Platform`" +
                ", SUM(`Beans_PlatformReturn`) AS `Beans_PlatformReturn`" +
                ", SUM(`Gift_UserCount`) AS `Gift_UserCount`" +
                ", SUM(`Gift_Count`) AS `Gift_Count`" +
                ", SUM(`Gift_Num`) AS `Gift_Num`" +
                ", SUM(`Gift_Coin`) AS `Gift_Coin`" +
                ", SUM(`Gift_LuckyCoin`) AS `Gift_LuckyCoin`" +
                ", SUM(`Gift_PondCoin`) AS `Gift_PondCoin`" +
                ", SUM(`Horn_UserCount`) AS `Horn_UserCount`" +
                ", SUM(`Horn_Count`) AS `Horn_Count`" +
                ", SUM(`Horn_Coin`) AS `Horn_Coin`" +
                ", SUM(`Guardian_UserCount`) AS `Guardian_UserCount`" +
                ", SUM(`Guardian_Count`) AS `Guardian_Count`" +
                ", SUM(`Guardian_Coin`) AS `Guardian_Coin`" +
                ", SUM(`VIP_UserCount`) AS `VIP_UserCount`" +
                ", SUM(`VIP_Count`) AS `VIP_Count`" +
                ", SUM(`VIP_Coin`) AS `VIP_Coin`" +
                ", SUM(`Mounts_UserCount`) AS `Mounts_UserCount`" +
                ", SUM(`Mounts_Count`) AS `Mounts_Count`" +
                ", SUM(`Mounts_Coin`) AS `Mounts_Coin`" +
                ", SUM(`Lottery_Coin`) AS `Lottery_Coin`" +
                ", SUM(`Lottery_Count`) AS `Lottery_Count`" +
                ", SUM(`Lottery_UserCount`) AS `Lottery_UserCount`" +
                ", SUM(`Lottery_WinningAmt`) AS `Lottery_WinningAmt`" +
                ", SUM(`User_Coin_Count`) AS `User_Coin_Count`" +
                ", SUM(`User_Coin_Amt`) AS `User_Coin_Amt`" +
                ", SUM(`User_Beans_Count`) AS `User_Beans_Count`" +
                ", SUM(`User_Beans_Amt`) AS `User_Beans_Amt`" +
                ", SUM(`Trade_Coin_UserCount`) AS `Trade_Coin_UserCount`" +
                ", SUM(`Trade_Coin_Count`) AS `Trade_Coin_Count`" +
                ", SUM(`Trade_Coin_Count_In`) AS `Trade_Coin_Count_In`" +
                ", SUM(`Trade_Coin_Count_Out`) AS `Trade_Coin_Count_Out`" +
                ", SUM(`Trade_Coin_Amt`) AS `Trade_Coin_Amt`" +
                ", SUM(`Trade_Coin_Amt_In`) AS `Trade_Coin_Amt_In`" +
                ", SUM(`Trade_Coin_Amt_Out`) AS `Trade_Coin_Amt_Out`" +
                ", SUM(`Trade_Beans_UserCount`) AS `Trade_Beans_UserCount`" +
                ", SUM(`Trade_Beans_Count`) AS `Trade_Beans_Count`" +
                ", SUM(`Trade_Beans_Count_In`) AS `Trade_Beans_Count_In`" +
                ", SUM(`Trade_Beans_Count_Out`) AS `Trade_Beans_Count_Out`" +
                ", SUM(`Trade_Beans_Amt`) AS `Trade_Beans_Amt`" +
                ", SUM(`Trade_Beans_Amt_In`) AS `Trade_Beans_Amt_In`" +
                ", SUM(`Trade_Beans_Amt_Out`) AS `Trade_Beans_Amt_Out`";
            switch (parm.Group) {
                case "Day":
                    PageParm.ColumnPK = "`Report_Day`";
                    PageParm.TableList = "(" +
                        " SELECT `Report_Day`" +
                        "  , '' AS `Channel_ID`" +
                        "  , COUNT(DISTINCT `Channel_ID`) AS `Channel_ID_Count`" +
                        PageParm.TableList +
                        " FROM `channel_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Report_Day`" +
                        ") AS `tabChannelDay`";
                    PageParm.Condition = "";
                    break;
                case "Channel":
                    PageParm.ColumnPK = "`Channel_ID`";
                    PageParm.TableList = "(" +
                        " SELECT '' AS `Report_Day`" +
                        "  , COUNT(DISTINCT `Report_Day`) AS `Report_Day_Count`" +
                        "  ,`Channel_ID`" +
                        PageParm.TableList +
                        " FROM `channel_day`" +
                        (PageParm.Condition ? " WHERE " + PageParm.Condition : "") +
                        " GROUP BY `Channel_ID`" +
                        ") AS `tabChannelDay`";
                    PageParm.Condition = "";
                    break;
                default:
                    PageParm.ColumnPK = "`Channel_ID`";
                    PageParm.TableList = "`channel_day`";
                    break;
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        ChannelDay_Parm: function () {
            return {
                FuzzyQuery: "",
                Channel_ID: "",
                Effective: -1,
                StartDate: "",
                EndDate: "",
                Group: ""
            };
        },
        //endregion


        //region AnchorDayStatistics:每日艺人统计列表
        AnchorDayStatistics: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`anchor_day`.`User_ID`";
            PageParm.ColumnMAX = "`anchor_day`.`User_ID`";
            PageParm.ColumnList = "`anchor_day`.`User_ID`" +
                ", `anchor_day`.`Report_Day`" +
                ", `anchor_day`.`Family_ID`" +
                ", `anchor_day`.`Family_Name`" +
                ", `anchor_day`.`NickName`" +
                ", `anchor_day`.`RealName`" +
                ", `anchor_day`.`Coin`" +
                ", `anchor_day`.`Beans_Anchor`" +
                ", `anchor_day`.`Beans_Family`" +
                ", `anchor_day`.`Beans_Platform`" +
                ", `anchor_day`.`Live_Count`" +
                ", `anchor_day`.`Live_Duration`" +
                ", `anchor_day`.`Live_Duration_Efftive`" +
                ", `anchor_day`.`Gift_Count`" +
                ", `anchor_day`.`Gift_Num`" +
                ", `anchor_day`.`Gift_Coin`" +
                ", `anchor_day`.`Gift_Beans_Anchor`" +
                ", `anchor_day`.`Gift_Beans_Family`" +
                ", `anchor_day`.`Gift_Beans_Platform`" +
                ", `anchor_day`.`Gift_Pond_Count`" +
                ", `anchor_day`.`Gift_Pond_Coin`" +
                ", `anchor_day`.`Guardian_Count`" +
                ", `anchor_day`.`Guardian_Coin`" +
                ", `anchor_day`.`Guardian_Beans_Anchor`" +
                ", `anchor_day`.`Guardian_Beans_Family`" +
                ", `anchor_day`.`Guardian_Beans_Platform`" +
                ", `anchor_day`.`Horn_Count`" +
                ", `anchor_day`.`Horn_Coin`" +
                ", `anchor_day`.`Horn_Beans_Anchor`" +
                ", `anchor_day`.`Horn_Beans_Family`" +
                ", `anchor_day`.`Horn_Beans_Platform`" +
                ", `anchor_day`.`User_SignUp_Count`";
            PageParm.TableList = "`anchor_day`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "Report_Day" + " " + "DESC";
            }
            //按ID查询
            if (parm.User_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`User_ID` = :User_ID", "AND");
            }
            //按公会查询
            if (parm.Family_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`Family_ID` = :Family_ID", "AND");
            }
            if (parm.Create_Date_Between && parm.Create_Date_And) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "DATE_FORMAT(`anchor_day`.`Report_Day`,'%Y-%m-%d') >= :Create_Date_Between AND DATE_FORMAT(`anchor_day`.`Report_Day`,'%Y-%m-%d') < :Create_Date_And", "AND");
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        AnchorDayStatistics_Parm: function () {
            return {
                User_ID: null,//ID
                Report_Day: null,//创建时间
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        },
        //endregion
        //region FamilyAnchorMonthStatistics:每日公会艺人统计列表
        FamilyAnchorMonthStatistics: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`anchor_day`.`User_ID`";
            PageParm.ColumnMAX = "`anchor_day`.`User_ID`";
            PageParm.ColumnList = "`anchor_day`.`Sum_BeansAnchor`" +
                ", `anchor_day`.`Sum_LiveDuring`" +
                ", `anchor_day`.`Sum_LiveDuring_Efftive`" +
                ", `anchor_day`.`User_ID`" +
                ", `anchor_day`.`Family_ID`" +
                ", `anchor_day`.`Report_Day`" +
                ", `anchor_day`.`Month`" +
                ", `anchor_day`.`Sum_Efftive`" +
                ", `user_info`.`NickName`";
            PageParm.TableList = " (SELECT SUM(`Beans_Anchor_Task`) AS `Sum_BeansAnchor`" +
                ", SUM(`Live_Duration`) AS `Sum_LiveDuring`" +
                ", SUM(`Live_Duration_Efftive`) AS `Sum_LiveDuring_Efftive`" +
                ", `User_ID`" +
                ", `NickName`" +
                ", `Family_ID`" +
                ", `Report_Day`" +
                ", DATE_FORMAT(`Report_Day`,'%Y-%c') AS Month" +
                ", SUM(CASE WHEN `Live_Duration_Efftive` >= 120 THEN 1 ELSE 0 END ) AS `Sum_Efftive`" +
                " FROM `anchor_day` GROUP BY DATE_FORMAT(`Report_Day`,'%Y-%c'),`Family_ID`,`User_ID`) AS `anchor_day`" +
                " JOIN `koc-anchor-user`.`user_info` AS `user_info` ON `user_info`.`User_ID` = `anchor_day`.`User_ID`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "Report_Day" + " " + "DESC";
            }
            //按ID查询
            if (parm.User_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`User_ID` = :User_ID", "AND");
            }
            //按NickName查询
            if (parm.NickName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`NickName` = :NickName", "AND");
            }
            //按公会查询
            if (parm.Family_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`Family_ID` = :Family_ID", "AND");
            }
            if (parm.Create_Date_Between && parm.Create_Date_And) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`Report_Day` >= :Create_Date_Between AND `anchor_day`.`Report_Day` < :Create_Date_And", "AND");
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        FamilyAnchorMonthStatistics_Parm: function () {
            return {
                Family_ID: null,
                User_ID: null,//ID
                Report_Day: null,//创建时间
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        },
        //endregion
        //region AdminAnchorStatistics:后台每日艺人统计列表
        AdminAnchorStatistics: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`anchor_day`.`User_ID`";
            PageParm.ColumnMAX = "`anchor_day`.`User_ID`";
            PageParm.ColumnList = "*";
            PageParm.TableList = " (SELECT SUM(`Beans_Anchor`) AS `Sum_BeansAnchor`" +
                ", SUM(`Live_Duration`) AS `Sum_LiveDuring`" +
                ", SUM(`Live_Duration_Efftive`) AS `Sum_LiveDuring_Efftive`" +
                ", `User_ID`" +
                ", `NickName`" +
                ", `Family_ID`" +
                ", SUM(CASE WHEN `Live_Duration_Efftive` >= 120 THEN 1 ELSE 0 END ) AS `Sum_Efftive`" +
                " FROM `anchor_day` WHERE DATE_FORMAT(`Report_Day`,'%Y-%m-%d') >= :Create_Date_Between AND DATE_FORMAT(`Report_Day`,'%Y-%m-%d') <= :Create_Date_And" +
                " GROUP BY `User_ID`,`Family_ID`) AS `anchor_day`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "User_ID" + " " + "DESC";
            }
            //按ID查询
            if (parm.User_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`User_ID` = :User_ID", "AND");
            }
            //按NickName查询
            if (parm.NickName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`NickName` = :NickName", "AND");
            }
            //按公会查询
            if (parm.Family_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`Family_ID` = :Family_ID", "AND");
            }
            if (!parm.Create_Date_Between || !parm.Create_Date_And) {
                parm.Create_Date_Between = KOC.Moment().subtract(10, 'year')._d;
                parm.Create_Date_And = KOC.Moment()._d;
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        AdminAnchorStatistics_Parm: function () {
            return {
                User_ID: null,//ID
                NickName: null,//昵称
                Family_ID: null,//公会ID
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        },
        //endregion
        //region AdminFamilyStatistics:后台每日公会统计列表
        AdminFamilyStatistics: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`anchor_day`.`Family_ID`";
            PageParm.ColumnMAX = "`anchor_day`.`Family_ID`";
            PageParm.ColumnList = "`anchor_day`.`Sum_BeansAnchor`" +
                ", `anchor_day`.`Family_ID`" +
                ", `anchor_day`.`Family_Name`";
            PageParm.TableList = " (SELECT SUM(`Beans_Anchor`) AS `Sum_BeansAnchor`" +
                ", `Family_Name`" +
                ", `Family_ID`" +
                " FROM `anchor_day` WHERE DATE_FORMAT(`Report_Day`,'%Y-%m-%d') >= :Create_Date_Between AND DATE_FORMAT(`Report_Day`,'%Y-%m-%d') <= :Create_Date_And " +
                " GROUP BY Family_ID) AS `anchor_day`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "Family_ID" + " " + "DESC";
            }
            //模糊查询
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`anchor_day`.`Family_Name` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`anchor_day`.`Family_ID` LIKE :FuzzyQueryLike", "OR");
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            //按NickName查询
            if (parm.Family_Name) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`Family_Name` LIKE :Family_Name", "AND");
            }
            //按公会查询
            if (parm.Family_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`anchor_day`.`Family_ID` = :Family_ID", "AND");
            }
            if (!parm.Create_Date_Between || !parm.Create_Date_And) {
                parm.Create_Date_Between = KOC.Moment().subtract(10, 'year')._d;
                parm.Create_Date_And = KOC.Moment()._d;
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        AdminFamilyStatistics_Parm: function () {
            return {
                User_ID: null,//ID
                NickName: null,//昵称
                Family_ID: null,//公会ID
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        },
        //endregion
        //region PlatformDayStatistics:每日平台统计列表
        PlatformDayStatistics: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`platform_day`.`Report_Day`";
            PageParm.ColumnMAX = "`platform_day`.`Report_Day`";
            PageParm.ColumnList = "`platform_day`.`Report_Day`" +
                ", `platform_day`.`User_Count`" +
                ", `platform_day`.`User_Count_SignUp`" +
                ", `platform_day`.`User_Count_SignIn`" +
                ", `platform_day`.`User_Count_VIP`" +
                ", `platform_day`.`User_Count_Consumption`" +
                ", `platform_day`.`User_Coin`" +
                ", `platform_day`.`User_Beans`" +
                ", `platform_day`.`Anchor_Count`" +
                ", `platform_day`.`Anchor_Count_SignUp`" +
                ", `platform_day`.`Anchor_Count_SignIn`" +
                ", `platform_day`.`Anchor_Count_Live`" +
                ", `platform_day`.`Family_Count`" +
                ", `platform_day`.`Family_Count_SignUp`" +
                ", `platform_day`.`Family_Beans`" +
                ", `platform_day`.`Live_Count`" +
                ", `platform_day`.`Live_Duration`" +
                ", `platform_day`.`Recharge_User`" +
                ", `platform_day`.`Recharge_Count`" +
                ", `platform_day`.`Recharge_Money`" +
                ", `platform_day`.`Recharge_Coin`" +
                ", `platform_day`.`Recharge_Poundage`" +
                ", `platform_day`.`Gift_Count`" +
                ", `platform_day`.`Gift_Num`" +
                ", `platform_day`.`Gift_Coin`" +
                ", `platform_day`.`Gift_Beans_Anchor`" +
                ", `platform_day`.`Gift_Beans_Family`" +
                ", `platform_day`.`Gift_Beans_Platform`" +
                ", `platform_day`.`Gift_Pond_Count`" +
                ", `platform_day`.`Gift_Pond_Coin`" +
                ", `platform_day`.`Guardian_Count`" +
                ", `platform_day`.`Guardian_Coin`" +
                ", `platform_day`.`Guardian_Beans_Anchor`" +
                ", `platform_day`.`Guardian_Beans_Family`" +
                ", `platform_day`.`Guardian_Beans_Platform`" +
                ", `platform_day`.`Horn_Count`" +
                ", `platform_day`.`Horn_Coin`" +
                ", `platform_day`.`Horn_Beans_Anchor`" +
                ", `platform_day`.`Horn_Beans_Family`" +
                ", `platform_day`.`Horn_Beans_Platform`" +
                ", `platform_day`.`Horn_Beans_Platform_Package`" +
                ", `platform_day`.`Gift_Count_Package`" +
                ", `platform_day`.`Gift_Num_Package`" +
                ", `platform_day`.`Gift_Coin_Package`" +
                ", `platform_day`.`Gift_Beans_Anchor_Package`" +
                ", `platform_day`.`Gift_Beans_Family_Package`" +
                ", `platform_day`.`Gift_Beans_Platform_Package`" +
                ", `platform_day`.`Horn_Count_Package`" +
                ", `platform_day`.`Horn_Coin_Package`" +
                ", `platform_day`.`Horn_Beans_Anchor_Package`" +
                ", `platform_day`.`Horn_Beans_Family_Package`" +
                ", `platform_day`.`Lottery_Winning_Value`" +
                ", `platform_day`.`VIP_User`" +
                ", `platform_day`.`VIP_Count`" +
                ", `platform_day`.`VIP_Coin`" +
                ", `platform_day`.`Mounts_User`" +
                ", `platform_day`.`Mounts_Count`" +
                ", `platform_day`.`Gift_Count_Lucky`" +
                ", `platform_day`.`Gift_Lucky_Coin`" +
                ", `platform_day`.`Gift_Coin_Lucky`" +
                ", `platform_day`.`Gift_Num_Lucky`" +
                ", `platform_day`.`Lottery_Coin`" +
                ", `platform_day`.`Lottery_CategoryIron_Coin`" +
                ", `platform_day`.`Lottery_CategoryCopper_Coin`" +
                ", `platform_day`.`Lottery_CategorySilver_Coin`" +
                ", `platform_day`.`Lottery_CategoryGold_Coin`" +
                ", `platform_day`.`Lottery_Count`" +
                ", `platform_day`.`Lottery_CategoryIron_Count`" +
                ", `platform_day`.`Lottery_CategoryCopper_Count`" +
                ", `platform_day`.`Lottery_CategorySilver_Count`" +
                ", `platform_day`.`Lottery_CategoryGold_Count`" +
                ", `platform_day`.`Lottery_Winning_Value`" +
                ", `platform_day`.`Mounts_Coin`";
            PageParm.TableList = "`platform_day`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "Report_Day" + " " + "DESC";
            }
            // //按创建日期查询
            if (parm.Create_Date_Between && parm.Create_Date_And) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "DATE_FORMAT(`platform_day`.`Report_Day`,'%Y-%m-%d') >= :Create_Date_Between AND DATE_FORMAT(`platform_day`.`Report_Day`,'%Y-%m-%d') <= :Create_Date_And", "AND");
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        PlatformDayStatistics_Parm: function () {
            return {
                Report_Day: null,//创建时间
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        },
        //endregion
        //region ChannelDayStatistics:渠道统计列表
        ChannelDayStatistics: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`channel_day_`.`Channel_ID`";
            PageParm.ColumnMAX = "`channel_day_`.`Channel_ID`";
            PageParm.ColumnList = "`channel_day_`.`Channel_ID`" +
                ", `channel_day_`.`Report_Day`" +
                ", `channel_day_`.`Channel_ID`" +
                ", `channel_day_`.`Recharge_User`" +
                ", `channel_day_`.`Recharge_Money`" +
                ", `channel_day_`.`Recharge_Count`" +
                ", `channel_day_`.`Recharge_Coin`" +
                ", `channel_day_`.`Recharge_Poundage`" +
                ", `channel_day_`.`User_Count_SignIn`" +
                ", `channel_day_`.`User_Count_SignUp`";
            PageParm.TableList = "`channel_day_`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "Report_Day" + " " + "DESC";
            }
            //按ID查询
            if (parm.Channel_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`channel_day_`.`Channel_ID` = :Channel_ID", "AND");
            }
            //按创建日期查询
            if (parm.Report_Day) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`channel_day_`.`Report_Day` = :Report_Day", "AND");
            }
            if (parm.Create_Date_Between && parm.Create_Date_And) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "DATE_FORMAT(`channel_day_`.`Report_Day`,'%Y-%m-%d') >= :Create_Date_Between AND DATE_FORMAT(`channel_day_`.`Report_Day`,'%Y-%m-%d') <= :Create_Date_And", "AND");
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        ChannelDayStatistics_Parm: function () {
            return {
                Channel_ID: null,//ID
                Report_Day: null,//创建时间
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        }
        //endregion
    }
    //endregion
};